package com.czxy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.czxy.domain.Teacher;
import com.czxy.mapper.TeacherMapper;
import com.czxy.service.TeacherService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {


    public Teacher login(Teacher tea) {
        //1 创建queryWarpper，根据名字去数据库查找老师信息
        QueryWrapper<Teacher> queryWrapper = new QueryWrapper<Teacher>();
        queryWrapper.eq("tea_name",tea.getTeaName());

        Teacher dbTeacher = baseMapper.selectOne(queryWrapper);

        //2 根据数据库返回的老师信息，比较密码是否正确
        if (dbTeacher!=null){
            if (dbTeacher.getPassword().equals(tea.getPassword())){
                return dbTeacher;
            }
        }
        return null;
    }
}